$(function () {
    let allTypesStatus = false;
    let sortRuleStatus = false;
    const allTypes = $("#all_types");
    const sortRule = $("#sort_rule");
    const allTypesContainer = $("#all_types_container");
    const sortRuleContainer = $("#sort_rule_container");

    function process_myself_status(show_val, icon_val, status, mode) {
        if (status === true) {
            if (mode === 1) {
                allTypesStatus = false
            } else {
                sortRuleStatus = false;
            }
            show_val.hide();
            icon_val.find("span").find("span").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
        } else {
            if (mode === 1) {
                allTypesStatus = true
            } else {
                sortRuleStatus = true;
            }
            show_val.show();
            icon_val.find("span").find("span").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
        }
    }

    function process_other_status(show_val, icon_val) {
        allTypesStatus = false
        sortRuleStatus = false;
        show_val.hide()
        icon_val.find("span").find("span").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
    }

    // 处理子分类点击
    allTypes.click(function () {
        if (sortRuleStatus) {
            process_other_status(sortRuleContainer, sortRule);
        } else {
            process_myself_status(allTypesContainer, allTypes, allTypesStatus, 1);
        }
    })

    // 处理点击别处收起子分类选择
    allTypesContainer.click(function () {
        process_other_status(allTypesContainer, allTypes);
    })

    // 处理排序点击
    sortRule.click(function () {
        if (allTypesStatus) {
            process_other_status(allTypesContainer, allTypes);
        } else {
            process_myself_status(sortRuleContainer, sortRule, sortRuleStatus, 2);
        }
    })

    // 处理点击别处收起配排序选择
    sortRuleContainer.click(function () {
        process_other_status(sortRuleContainer, sortRule);
    })
})

